package com.javasm.mb_store_api_final.giftsandgoods.goods.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javasm.common.R;
import com.javasm.mb_store_api_final.giftsandgoods.goods.entity.GgGoods;
import com.javasm.mb_store_api_final.giftsandgoods.goods.service.GgGoodsService;
import com.javasm.mb_store_api_final.giftsandgoods.goods.vo.GidVo;
import com.javasm.mb_store_api_final.giftsandgoods.goods.vo.GoodsVo;
import com.javasm.mb_store_api_final.giftsandgoods.goodsBrand.entity.GgBrand;
import com.javasm.mb_store_api_final.giftsandgoods.goodsBrand.service.GgBrandService;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.entity.GgSupplier;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.service.GgSupplierService;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.entity.GgGoodsType;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.service.GgGoodsTypeService;
import com.qiniu.util.Json;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lh
 * @version 0.1
 * @className GoodsController
 * @date 2024/7/29 21:21
 * @description
 * @since jdk11
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    GgGoodsService goodsService;
    @Resource
    GgBrandService brandService;
    @Resource
    GgGoodsTypeService typeService;//ggGoodsTypeService
    @Resource
    GgSupplierService supplierService;
    //获取商品列表
    @PostMapping("/list")
    public R selectGoodsList(@RequestBody GoodsVo goodsVo){
        IPage<GgGoods> page = goodsService.listWithTypeName(goodsVo);
        return R.ok(page);
    }
    //根据gid查询商品
    @PostMapping("/selectGoodsWithGid")
    public R selectGoodsWithGid(@RequestBody GidVo gidVo){
        GgGoods goods = goodsService.getByIdWithAnotherProperties(gidVo.getGid());
        return R.ok(goods);
    }
    //修改商品
    @PostMapping("/updateGoods")
    public R updateGoods(@RequestBody GgGoods goods){
        boolean b = goodsService.updateByIdWithClassify(goods);
        return R.ok(b);
    }
    //添加商品
    @PostMapping("/addGoods")
    public R addGoods(@RequestBody GgGoods goods){

        boolean save = goodsService.saveGoodsWithProduct(goods);
        return R.ok(save);
    }
    //根据gid删除商品
    @PostMapping("/deleteGoods")
    public R deleteGoods(@RequestBody GidVo gidVo){
        boolean b = goodsService.removeById(gidVo.getGid());
        return R.ok(b);
    }
    //获取品牌列表
    @GetMapping("/brand")
    public R selectBrandList(){
        List<GgBrand> brandList = brandService.list();
        return R.ok(brandList);
    }

    @GetMapping("/type")
    public R selectTypeList(){
        List<GgGoodsType> goodsTypeList = typeService.list();
        return R.ok(goodsTypeList);
    }
    @GetMapping("/supply")
    public R selectSupplierList(){
        List<GgSupplier> supplierList = supplierService.list();
        return R.ok(supplierList);
    }
    @GetMapping("/selectGoodsWithSid")
    public R selectGoodsWithSid(Integer sid){
        List<GgSupplier> supplierList = supplierService.list();
        return R.ok(supplierList);
    }


}
